﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Facebook.Web;
using Facebook.Api.DemoSite.Models.Demo;
using Facebook.Api.DemoSite.Models;
using Facebook.Web.Mvc;

namespace Facebook.Api.DemoSite.Controllers
{
    public partial class DemoController : FacebookMvcController
    {
        public ActionResult Notifications()
        {
            this.ViewData["Uid"] = this.FbContext.Session.Uid;
            var notifications = this.FbContext.Notifications.Get();
            //this.ViewData["MostRecent"] = notifications.Value.Messages.MostRecent;
            this.ViewData["UnreadCount"] = notifications.Value.Messages.Unread.ToString() ;
            return this.View();
        }

        public ActionResult NotificationsSend(String type, String ids, String notification)
        {
            String[] id_array = ids.Split(',');
            var result = this.FbContext.Notifications.Send(type, id_array, notification);
            this.ViewData["SuccessMessage"] = "Notification sent successfully";
            this.ViewData["ErrorMessage"] = "Error sending notification";
            this.PostResult = this.PartialView("AsyncPostResult", result);
            return null;
        }

        public ActionResult NotificationsSendEmail(String ids, String subject, String notification, String fbml)
        {
            String[] id_array = ids.Split(',');
            var result = this.FbContext.Notifications.SendEmail(id_array, subject, notification, fbml);
            this.ViewData["SuccessMessage"] = "Notification email sent successfully";
            this.ViewData["ErrorMessage"] = "Error sending notification email";
            this.PostResult = this.PartialView("AsyncPostResult", result);
            return null;
        }
    }
}